home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fatted Calf
/
The Fatted Calf.iso
/
Applications
/
Audio
/
Patchmix
/
XWindowsSource
/
list.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-28
|
2KB
|
110 lines
static char rcsid[] = "$Header: list.c,v 1.1 90/08/27 17:09:02 mara Exp $";
/* list.c
*
* Written by Mara Helmuth
*
* Description: List class for Cmix X graphical interface
*
* $Log: list.c,v $
* Revision 1.1 90/08/27 17:09:02 mara
* Initial revision
*
* Revision 1.2 90/01/30 10:57:29 mara
* *** empty log message ***
*
* Revision 1.1 90/01/21 12:41:48 mara
* Initial revision
*
*/
#include <g++/stdio.h>
#include "plus.h"
void list::insert(char* a)
{
node* temp;
temp = new node;
temp -> contents = new char[size];
if (!temp -> contents)
perror("list::insert()");
for (int i=0; i<size; i++)
temp -> contents[i] = a[i];
if (head) {
temp -> next = head;
head = temp;
}
else {
temp -> next = 0;
head = temp;
}
top = head;
}
void list::append(char* a)
{
node *previous,*current,*newnode;
if (head)
{
previous = head;
current = head -> next;
while (current) {
previous = current;
current = current -> next;
}
newnode = new node;
newnode -> contents = new char[size];
if (!newnode -> contents)
errx("list::append()");
newnode -> next = 0;
for (int i=0; i<size; i++)
newnode -> contents[i] = a[i];
previous -> next = newnode;
}
else {
head = new node;
top = head;
head -> contents = new char[size];
if (!head -> contents)
errx("list::append()");
head -> next = 0;
for (int i=0; i<size; i++)
head -> contents[i] = a[i];
}
}
char* list::get() // get item from list
{
if (!head)
return 0;
else {
char* r = new char[size];
if (!r)
errx("list::get()");
node* f = head;
for (int i=0; i<size; i++)
r[i] = f -> contents[i];
head = head -> next;
return r;
}
}
void list::clear()
{
node* n = top;
if (!n)
return;
while (n) {
node* nd = n;
n = n -> next;
delete nd -> contents;
delete nd;
}
head = 0;
top = 0;
}